Arrays and Slices in Odin
Table of Contents
1. Enumerated Arrays
We can use enum member names as indices for a fixed array.
Nice_People :: enum {
Bob,
Klucke,
Tim,
}
rating := [Nice_People]int {
.Bob = 5,
.Klucke = 7,
.Tim = 3,
}
bob_rating := rating[.Bob]
We may also skip initializing the enumerated array. Then, all of them would be zero-valued.
We can also do partial initialization. All non-mentioned items will be zero.
nice_rating := #partial [Nice_People]int {
.Klucke = 10,
}
2. Small Array: Pseudo-Growing Fixed-Memory Array
ALthough it provides methods like append(), but in essence, it’s a fixed array with maximum capacity and automatically keeps track of the length.